package com.fesine.quartz.chapter3;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * @description: 简单调度器实现
 * @author: Fesine
 * @createTime:2016/11/16 8:34
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/11/16 8:34
 */
public class SimpleScheduler {
    static Log logger = LogFactory.getLog(SimpleScheduler.class);

    public static void main(String[] args) {
        SimpleScheduler scheduler = new SimpleScheduler();
        scheduler.startScheduler();
    }

    private void startScheduler() {
        Scheduler scheduler = null;
        try {
            scheduler = StdSchedulerFactory.getDefaultScheduler();
            scheduler.start();
            logger.info("调度器启动：" + new Date());
        } catch (SchedulerException e) {
            logger.error(e);
        }
    }

    private void modifyScheduler(Scheduler scheduler) {
        try {
            //判断调度器是不是暂停模式，如果不是则暂停当前调度器
            if (!scheduler.isInStandbyMode()) {
                scheduler.standby();
            }
            //重启调度器
            scheduler.start();
        } catch (SchedulerException e) {
            logger.error(e);
        }
    }
}
